<template>
  <div class="user-management-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="12">
        <el-select v-model="value" clearable placeholder="请选择审核状态">
          <el-option
            v-for="item in options1"
            :key="item.id"
            :label="item.creClasName"
            :value="item.id"
            @click.native="optosall(item)"
          />
        </el-select>
      </vab-query-form-left-panel>

      <vab-query-form-right-panel :span="12">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyWord"
              clearable
              placeholder="请输入用户名"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      border
      :data="list"
      @selection-change="setSelectRows"
      @sort-change="tableSortChange"
    >
      <el-table-column align="center" show-overflow-tooltip type="selection" />
      <el-table-column
        align="center"
        label="数字id"
        prop="digitalId"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="openId"
        prop="openId"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="姓名"
        prop="name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="联系电话"
        prop="phone"
        show-overflow-tooltip
      />

      <el-table-column align="center" label="身份证照片">
        <template #default="{ row }">
          <el-image
            v-if="row.idCardFront"
            :preview-src-list="imageList"
            :src="row.idCardFront"
          />
          <span v-else>暂无照片</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="身份证号码"
        prop="idCardNum"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="实名信息">
        <template slot-scope="scope">
          {{ scope.row.name }}
          <br />

          <img
            class="el-avatar el-avatar--circle"
            :src="scope.row.headPortrait"
          />
        </template>
      </el-table-column>

      <el-table-column align="center" label="审核状态" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="scope.row.realName == 0">
            <span style="color: red">实名未审</span>
          </template>
          <template v-else-if="scope.row.realName == 1">
            <span style="color: gray">实名待审中</span>
          </template>
          <template v-else-if="scope.row.realName == 2">
            <span style="color: green">实名成功</span>
          </template>
          <template v-else-if="scope.row.realName == 3">
            <span style="color: red">实名未通过</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="注册时间"
        prop="creationTime"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作"
        show-overflow-tooltip
        width="85"
      >
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">处理</el-button>
          <!-- <el-button type="text" @click="handleDelete(row)">停用</el-button>  -->
        </template>
      </el-table-column>
      <template #empty>
        <el-image
          class="vab-data-empty"
          :src="require('@/assets/empty_images/data_empty.png')"
        />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <edit ref="edit" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { getList } from '@/api/shiming'
  import Edit from './model/chuli.vue'

  export default {
    name: 'UserManagement',
    components: { Edit },
    data() {
      return {
        imageList: [],
        value: '',
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          checkValue: '', //审核的结果
          // name: '',
          // nickname: '',
          // openId: '',
          // locked: '',
          // phone: '',
          // headPortrait: '',
        },
        options1: [
          {
            id: '1',
            creClasName: '待审核',
          },
          {
            id: '2',
            creClasName: '审核通过',
          },
          {
            id: '3',
            creClasName: '审核未通过',
          },
        ], //审核状态
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      tableSortChange() {
        const imageList = []
        this.$refs.tableSort.tableData.forEach((item) => {
          imageList.push(item.img)
        })
        this.imageList = imageList
      },
      async optosall(e) {
        this.queryForm.checkValue = e.id
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      setSelectRows(val) {
        this.selectRows = val
      },
      handleEdit(row) {
        console.log(row)
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        } else {
          this.$refs['edit'].showEdit()
        }
      },
      // handleDelete(row) {
      //   if (row.id) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       const { msg } = await doDelete({ id: row.id })
      //       this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //       await this.fetchData()
      //     })
      //   } else {
      //     if (this.selectRows.length > 0) {
      //       const id = this.selectRows.map((item) => item.id).join()
      //       this.$baseConfirm('你确定要删除选中项吗', null, async () => {
      //         const { msg } = await doDelete({ id })
      //         this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //         await this.fetchData()
      //       })
      //     } else {
      //       this.$baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
      //     }
      //   }
      // },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      // async fetchData() {
      //   this.listLoading = true
      //   const {....
      //     data: { list, total },
      //   } = await getList(this.queryForm)
      //   this.list = list
      //   this.total = total
      //   this.listLoading = false
      // },
      async fetchData() {
        this.listLoading = true
        const res = await getList(this.queryForm)

        this.list = res.data.dataList

        this.total = res.data.total
        this.listLoading = false
        const imageList = []
        res.data.dataList.forEach((item) => {
          imageList.push(item.idCardFront)
          console.log(imageList)
        })
        this.imageList = imageList
      },
    },
  }
</script>
<style></style>
